package net.hn.hnms.biz.safety.trinity.dao;

import net.hn.hnms.biz.safety.trinity.entity.HiddenDangerAccept;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.sql.Timestamp;
import java.util.List;

/**
 * @author 智呈物联 nzw
 * @date 2022/8/4
 */
@Repository
public interface HiddenDangerAcceptDao extends JpaRepository<HiddenDangerAccept,String> {

    /**
     * 查询指定时间
     * @param timestamp
     * @return
     */
    @Query(value = "SELECT\n" +
            "\thda.* \n" +
            "FROM\n" +
            "\thidden_danger_accept hda,\n" +
            "\t( SELECT * FROM hidden_danger_list WHERE data_time >= ?) hdl \n" +
            "WHERE\n" +
            "\thda.danger_id = hdl.danger_id",nativeQuery = true)
    List<HiddenDangerAccept> findbyHiddenDangerList(Timestamp timestamp);

    /**
     * 查询验收通过的隐患
     * @return
     */
    @Query(value = "SELECT\n" +
            "\t*  \n" +
            "FROM\n" +
            "\thidden_danger_accept \n" +
            "WHERE\n" +
            "\taccept_result = '01'",nativeQuery = true)
    List<HiddenDangerAccept> ClosedLoopCount();

    /**
     * 查询未通过的隐患
     * @return
     */
    @Query(value = "SELECT \n" +
            "\t *  \n" +
            "FROM\n" +
            "\thidden_danger_accept \n" +
            "WHERE\n" +
            "\taccept_result = '02'",nativeQuery = true)
    List<HiddenDangerAccept> NotClosedLoopCount();


    @Query(value = "SELECT COUNT\n" +
            "\t( * ) \n" +
            "FROM\n" +
            "\thidden_danger_accept",nativeQuery = true)
    int countAll();

    @Query(value = "SELECT COUNT\n" +
            "\t( * ) \n" +
            "FROM\n" +
            "\thidden_danger_accept \n" +
            "WHERE\n" +
            "\taccept_date <= ?",nativeQuery = true)
    int countAllTaccept(Timestamp timestamp);

}
